package org.wheel.plugins.starter.jdbc.pool.service;

import org.wheel.module.core.entity.vo.Message;
import org.wheel.module.core.request.ApiParam;
import org.wheel.module.core.util.Page;
import org.wheel.plugins.toolkit.sql.core.LambdaDeleteWrapper;
import org.wheel.plugins.toolkit.sql.core.LambdaQueryWrapper;
import org.wheel.plugins.toolkit.sql.core.LambdaUpdateWrapper;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * 通用 Service 层接口
 * @param <T> 实体类型
 */
public interface BaseService<T> {

    /* ---------- 查询 ---------- */
    public Message selectByParam(LambdaQueryWrapper<T> wrapper, ApiParam apiParam);

    public <E> Message selectByParam(LambdaQueryWrapper<T> wrapper, ApiParam apiParam, Class<E> targetClass);

    T getById(Serializable id);

    <E> E getById(Serializable id, Class<E> beanClass);

    List<T> listByIds(Collection<? extends Serializable> ids);

    <E> List<E> listByIds(Collection<? extends Serializable> ids, Class<E> beanClass);

    T getOne(LambdaQueryWrapper<T> wrapper);

    <E> E getOne(LambdaQueryWrapper<T> wrapper, Class<E> beanClass);

    List<T> listAll(LambdaQueryWrapper<T> wrapper);

    <E> List<E> listAll(LambdaQueryWrapper<T> wrapper, Class<E> beanClass);

    List<T> list(LambdaQueryWrapper<T> wrapper);

    <E> List<E> list(LambdaQueryWrapper<T> wrapper, Class<E> beanClass);

    long count(LambdaQueryWrapper<T> wrapper);

    boolean exists(LambdaQueryWrapper<T> wrapper);

    /* ---------- 分页 ---------- */
    <E> Page<E> page(Page<E> page, LambdaQueryWrapper<T> wrapper, Class<E> targetClass);

    Page<T> page(Page<T> page, LambdaQueryWrapper<T> wrapper);

    /* ---------- 新增 ---------- */
    boolean save(T entity);

    boolean save(T entity, String opUserId);
    /**
     * 新增并返回主键（主键已回写到 entity）
     */
    T saveAndGetId(T entity);

    T saveAndGetId(T entity, String opUserId);

    /* ---------- 修改 ---------- */
    boolean updateById(T entity);

    boolean updateById(T entity, String opUserId);

    boolean updateById(T entity, boolean updateNull);

    boolean updateById(T entity, boolean updateNull, String opUserId);

    /* ---------- 删除 ---------- */
    boolean removeById(Serializable id);

    boolean logicRemoveById(Serializable id, String opUserId);

    boolean remove(LambdaDeleteWrapper<T> wrapper);

    boolean logicRemove(LambdaUpdateWrapper<T> wrapper, String opUserId);

    /* ---------- 批量操作 ---------- */
    boolean saveBatch(Collection<T> entities);
    boolean saveBatch(Collection<T> entities, String opUserId);
    boolean updateBatchById(Collection<T> entities);
    boolean updateBatchById(Collection<T> entities, String opUserId);
    boolean removeBatchByIds(Collection<? extends Serializable> ids);
    boolean logicRemoveBatchByIds(Collection<? extends Serializable> ids, String opUserId);
    boolean removeBatch(Collection<T> entities);
    boolean logicRemoveBatch(Collection<T> entities, String opUserId);
    boolean removeBatchWrapper(Collection<LambdaDeleteWrapper<T>> wrappers);
    boolean logicRemoveBatchWrapper(Collection<LambdaUpdateWrapper<T>> wrappers, String opUserId);
}
